<?php 
/***************************************************************
*  DYNAMO - Simple yet powerful CMS - www.dynamocms.com
*  Copyright (c) M31 2003-2008 - www.m31web.com
*
*  This script is part of the DYNAMO project. The DYNAMO
*  project is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html or included in the distribution
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
*
*  File Name: xxx.php
*      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
* 	
*  File Authors:
*      1.0 : Creation by Jean-Francois Faudi
* 
***************************************************************/

 	// include général et obligatoire
	require_once("../../configuration.php");

 	// verification de la session
	require_once("../scripting/check_session.php");
	
	// Definition des variables
	$address = getGlobalVar("address");
	$language = getGlobalVar("language");
	if ($language == "")
		$language = $default_language;

  	// langue pour l'administration
	require_once("../language/" . $admin_language . ".php");
	
 	// verification des droits webmaster ou administrateur
	if ($user_role < 200)
	{
		header("Location: ../admin/default.php?message=noid");
		exit();
	}
	
?>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Google Maps Popup</title>
    <style type="text/css">
    v\:* { behavior:url(#default#VML); }
	html, body { height:100%; min-height: 100%; }
    </style>
    <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=<?php print $googlemaps_key; ?>"
            type="text/javascript"></script>
    <script type="text/javascript">
<!--
//<![CDATA[
	
	var geocoder = new GClientGeocoder();
	var marker = 0;

	function updatecoords() {
		if (marker != 0) {
			//alert("updatecoords() called");
			var location = marker.getPoint();
			opener.document.myform.latitude.value = location.lat();
			opener.document.myform.longitude.value = location.lng();
		}
	}

	function centerMarker() {
		var point = map.getCenter();
		marker.setPoint(point);
		updatecoords();
	}


	function showAddress(address) {
	  geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			alert(address + " non trouvé");
		  } else {
			map.setCenter(point, 14);
			marker.setPoint(point);
			updatecoords();
			//marker.openInfoWindowHtml(address);
		  }
		}
	  )
	}
	
	function goAddress() {
		var address = document.getElementById("address").value;	
		showAddress(address);
	}
	
    function GLoad() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());

		//var address = opener.document.myform.address.value;
		//var country = opener.document.myform.country.value;
		//var location = address + ', ' + country;
		//document.getElementById("address").value = location;	

		var lat = (+opener.document.myform.latitude.value);
		var lng = (+opener.document.myform.longitude.value);
		var zoom = 14;
		//alert('Latitude=' + lat + ', Longitude=' + lng);
		if ((lat == 0) && (lng == 0))
		{
			lat = 43.551845;
			lng = 1.486244;
			zoom = 4;
		}	

		map.setCenter(new GLatLng(lat, lng), zoom);
		marker = new GMarker(new GLatLng(lat, lng), {draggable: true});
				
		map.addOverlay(marker);
		GEvent.addListener(marker, "dragend", updatecoords);

		//if ((lat == 0) && (lng == 0))
		//	goAddress();

		//map.setMapType(G_SATELLITE_MAP);
		//map.setMapType(G_HYBRID_MAP);
			
		//GEvent.addListener(map, "moveend", function() {
 		//	var wcenter = map.getCenter();
		//	opener.document.myform.latitude.value = wcenter.lat();
		//	opener.document.myform.longitude.value = wcenter.lng(); 
		//});

		//alert("GLoad() completed");
      }
    }

    //]]>

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
</script>
  </head>
  <body onload="GLoad(); window.focus();" onunload="GUnload();">
<table width="100%" border="0">
  <tr> 
    <td><form>
        <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
        <input name="address" type="text" id="address" onblur="goAddress();" onchange="goAddress();" size="40" />
        <input onclick="goAddress();" type="button" name="Submit" value="GO!" />
        <input onclick="centerMarker();" type="button" name="Submit" value="CTR" />
      </font></form></td>
  </tr>
  <tr> 
    <td><div id="map" style="width: 380px; height: 380px"></div></td>
  </tr>
</table>
  </body>
</html>